﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace HtmlExtractor.Processor
{
    public class EntityProcessor:IProcessor
    {
        public IDictionary<string, string> replaceReg = new Dictionary<string, string>();
        public EntityProcessor()
        {
            replaceReg.Add("&(quot|#34);", "\"");
            replaceReg.Add("&(gt|#62);", ">>");
            replaceReg.Add("&(amp|#38);", "&");
            replaceReg.Add("&(lt|#60);", "<<");
            replaceReg.Add("&(nbsp|#160);", "");
        }
        #region IProcessor Members

        public string GetResult(string text, ParserContext context)
        {
            foreach (KeyValuePair<string, string> kv in replaceReg)
            {
                text = SegmentRegex.Replace(text, kv.Key, kv.Value,RegexOptions.IgnoreCase);
            }
            return text;
        }

        #endregion
    }
}
